#include <iostream>
using namespace std;

/*
class A{
public:
    A(){
        cout << "A()" << endl;
    }
    ~A(){
        cout << "~A()" << endl;
    }
};

class Stack{
public:
    Stack(){
        cout << "Stack()" << endl;
        _a = new int[4];
        _top = 0;
        _capacity = 4;
    }
    ~Stack(){
        cout << "~Stack()" << endl;
        delete[] _a;
        _top = _capacity = 0;
    }
private:
    int* _a;
    int _top;
    int _capacity;
};

void test1(){
    int* p1 = new int[10];
    free(p1);
    A* p2 = new A;
    free(p2);
}

void test2(){
    Stack st;//自定义类型，出了作用域自动调用析构
    Stack* pst = new Stack;//内置类型，出了作用域不会调析构
    delete pst;
}

void test3(){
    A* p1 = new A[10];
    //free(p1);
    //delete p1;
    delete[] p1;
}

int main() {
    test3();
    return 0;
}
*/

//917. 仅仅反转字母
//https://leetcode.cn/problems/reverse-only-letters/

/*
class Solution {
public:
    static bool isLetter(char c){
        if (c >= 'a' && c <= 'z')
            return true;
        if (c >= 'A' && c <= 'Z')
            return true;
        return false;
    }
    static string reverseOnlyLetters(string s) {
        size_t begin = 0, end = s.size() - 1;
        while (begin < end){
            while (begin < end && !isLetter(s[begin]))
                ++begin;
            while (begin < end && !isLetter(s[end]))
                --end;
            swap(s[begin],s[end]);
            ++begin;
            --end;
        }
        return s;
    }
};

void test(){
    string s = "a-bcde-fdg";
    cout << s << endl;
    cout << Solution::reverseOnlyLetters(s) << endl;
}

 int main(){
    test();
    return 0;
}
*/

//387. 字符串中的第一个唯一字符
//https://leetcode.cn/problems/first-unique-character-in-a-string/

/*
class Solution {
public:
    static int firstUniqChar(string s) {
        int begin = 0;
        while (begin < s.size()){
            int tail = begin + 1;
            while (tail < s.size()){
                if (s[begin] == s[tail]){
                    ++begin;
                    break;
                } else
                    ++tail;
            }
            if (tail == s.size())
                return begin;
        }
        return -1;
    }
};
*/

/*
class Solution {
public:
    static int firstUniqChar(string s) {
        int count[26] = {0};
        for (auto ch:s) {
            ++count[ch - 'a'];
        }
        for (int i = 0; i < s.size(); ++i) {
            if (count[s[i]-'a'] == 1)
                return i;
        }
        return -1;
    }
};

int main(){
    string s1 = "leetcode";
    cout << Solution::firstUniqChar(s1) << endl;
    return 0;
}
*/

void test1(){
    string s1;
    string s2("hello world");
    string s3 = "chongqing";
    string s4(s3,2);
    string s5(10,'*');
    cout << s1 << endl;
    cout << s2 << endl;
    cout << s3 << endl;
    cout << s4 << endl;
    cout << s5 << endl;
}

void test2(){
    string s1 = "chongqing";
    cout << s1.size() << endl;
    cout << s1.capacity() << endl;
    s1.push_back('!');
    cout << s1 << endl;
    s1.append("hello");
    cout << s1 << endl;
    s1 += " world";
    cout << s1 << endl;
}

void test3(){
    string s = "hello";
    cout << sizeof(s) << endl;
    cout << s.size() << endl;
    cout << s.capacity() << endl;
    s.reserve(100);
    cout << s.size() << endl;
    cout << s.capacity() << endl;
    s.resize(200);
    cout << s.size() << endl;
    cout << s.capacity() << endl;
    s.resize(5);
    cout << s.size() << endl;
    cout << s.capacity() << endl;
}

void test4(){
    string s  = "hello world";
    string::iterator pc = s.begin();
    while (pc != s.end()){
        cout << *pc << ' ';
        ++pc;
    }
    cout << endl;
}

int main(){
    test4();
    return 0;
}